public class BinaryTree {
    //定义二叉树类
    static class TreeNode {
        public char val;
        public TreeNode left;
        public TreeNode right;
        //传入值val.
        public TreeNode(char val) {
            this.val = val;
        }
    }
    //穷举创建一颗二叉树,返回类型为二叉树
    public TreeNode creatTree() {          //定义的二叉树形状
        TreeNode A = new TreeNode('A');//              A
        TreeNode B = new TreeNode('B');//      B               C
        TreeNode C = new TreeNode('C');//  D       E       F       G
        TreeNode D = new TreeNode('D');//            H
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        E.right =H;
        C.left = F;
        C.right = G;
        return A;
    }
    //遍历二叉树
    //前序遍历
    public void proOrder(TreeNode root) {
        //判断为空就返回
        if(root == null) {
            return;
        }
        System.out.print(root.val+" ");
        proOrder(root.left);
        proOrder(root.right);
    }
    //中序遍历
    public void inOrder(TreeNode root) {
        if(root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val+" ");
        inOrder(root.right);
    }
    //后序遍历
    public void endOrder(TreeNode root) {
        if(root == null) {
            return;
        }
        endOrder(root.left);
        endOrder(root.right);
        System.out.print(root.val+" ");
    }
}
